﻿
CREATE TRIGGER trsec_t_Borrower_INSERT
ON dbo.t_Borrower
FOR INSERT
AS

SET NOCOUNT ON

IF (SELECT COUNT(*) FROM inserted) = 0 RETURN
IF dbo.Context_IsArchiveOff() > 0 RETURN
IF dbo.fn_ColumnsUpdated(COLUMNS_UPDATED(),@@PROCID) IN ('StatusID') RETURN

DECLARE @PK_1 nvarchar(256),@PK_2 nvarchar(256),@PK_3 nvarchar(256)
DECLARE @C int,@CC int SELECT @C = 1, @CC = COUNT(*) FROM inserted
DECLARE @BatchHID bigint,@HID bigint

SELECT * INTO #It_Borrower FROM
(SELECT ROW_NUMBER() OVER (ORDER BY ID) _ROW_, * FROM inserted) inserted

WHILE @C <= @CC AND @CC < 1000 BEGIN
	SELECT @PK_1=ID FROM #It_Borrower WHERE _ROW_ = @C
	DECLARE @SQL nvarchar(4000) SET @SQl = '#It_Borrower WHERE _ROW_='+CONVERT(varchar,@C)
	EXEC @HID = sp__sec__ArchiveRow @PK_1,@PK_2,@PK_3,@SQL,@BatchHID
	IF @BatchHID IS NULL SET @BatchHID = @HID
	SET @C = @C + 1
END
GO
EXECUTE sp_settriggerorder @triggername = N'[dbo].[trsec_t_Borrower_INSERT]', @order = N'first', @stmttype = N'insert';

